<?php


namespace app\apiadmin\model\choujiang;


use app\apiadmin\model\system\UserModel;
use app\common\utils\Res;
use think\facade\Db;
use think\Model;

class PrizeUserModel extends Model
{

    protected $name="siyu_prize_user";
    
    public static function list($param)
    {
        
        $pose_state =  ChouJiangModel::where('brid',$param['row']['brid'])->where('id',$param['row']['id'])->field('pose_state')->find();
        if ($pose_state['pose_state'] == 0){
            $result =   Db::table('xh_siyu_prize_user_lottery')
              ->alias('a')->join('xh_siyu_user b','a.user_id = b.id')
              ->join('xh_siyu_sys_member c','a.uid = c.uid')
              ->where('a.brid',$param['row']['brid'])
              ->where('a.prid',$param['row']['id'])
              ->where('a.state',1)
              ->field('a.brid,a.prid,a.uid,b.nickname,b.phone,c.nick_name,"是" as types')->select();
            return $result;
        }elseif ($pose_state['pose_state'] == 1){
            $res_data = Db::table('xh_siyu_prize_user')
                ->alias('a')
                ->join('xh_siyu_user b','a.user_id = b.id')
                ->join('xh_siyu_invitation_user i','i.wx_unionid = b.unionid')
                ->join('xh_siyu_sys_member m','m.user_name = i.sender')
                ->where('prid',$param['row']['id'])
                ->where('liveId',$param['row']['brid'])
                ->field('a.user_id,b.unionid,b.nickname,b.phone,m.nick_name as nick_name,"是" as types')
                ->select()->toArray();
          
            $robto = PrizeShuZiRenUserModel::where('prid',$param['row']['id'])->field('user_id')->select()->toArray();
           
            $bto_data = [];
            foreach ($robto  as $va){
                $bto_data[] = ShuZiRenModel::where('id',$va['user_id'])->field('nick as nickname,"否" as types')->find()->toArray();
            }
           
            $result =  array_merge($res_data,$bto_data);
            return $result;
        }
       
    }
    public static function total($param)
    {
        return UserModel::where('id',$param['row']['id'])->count();
    }
  
}